<!-- 功能  外接UPS弹窗 | 作者：menghao.yan | 邮箱：yxs2615@163.com | 时间：2023年08月24日 14:23:00 -->
<template>
  <!-- 弹出框 -->
  <a-modal v-model:open="visible" title="外接UPS" width="500px" class="y-modal" okText="创建" @ok="onSubmit" @cancel="onCancel">
    <a-card>
      <a-row align="middle">
        <a-col :span="12">
          <a-space>
            <a-button type="link" class="y-btn" @click="openWaiJieUpsSheZhiModal">
              <template #icon>
                <plus-outlined />
              </template>
              外接UPS设置
            </a-button>
            <!-- 弹窗 - 外接UPS设置 -->
            <waiJieUpsSheZhiModal v-model:visible="visibleWaiJieUpsSheZhiModal"></waiJieUpsSheZhiModal>
          </a-space>
        </a-col>
        <a-col :span="12">
          <a-input v-model:value="searchValue">
            <template #addonBefore>
              <search-outlined /> 搜索:
            </template>
          </a-input>
        </a-col>
      </a-row>
      <a-table bordered :data-source="dataSource" :columns="columns" class="y-table" :pagination="false">
      </a-table>
    </a-card>
  </a-modal>
</template>

<script setup>
import waiJieUpsSheZhiModal from './waiJieUpsSheZhiModal.vue'
const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  }
})

const { visible } = toRefs(props)

// 定义组件的事件
const emits = defineEmits(['update:visible'])

const visibleWaiJieUpsSheZhiModal = ref(false)

const openWaiJieUpsSheZhiModal = () => {
  visibleWaiJieUpsSheZhiModal.value = true
}

const searchValue = ref('')

// 表格列
const columns = ref([
  {
    title: '参数名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    sorter: {
      compare: (a, b) => a.name.localeCompare(b.name),
      multiple: 1
    }
  },
  {
    title: '参数值',
    dataIndex: 'kongZhiQi',
    key: 'kongZhiQi',
    align: 'center',
    sorter: {
      compare: (a, b) => a.kongZhiQi.localeCompare(b.kongZhiQi),
      multiple: 2
    }
  },
  {
    title: '备注',
    dataIndex: 'beiZhu',
    key: 'beiZhu',
    align: 'center',
    sorter: {
      compare: (a, b) => a.beiZhu.localeCompare(b.beiZhu),
      multiple: 3
    }
  }
])

// 表格数据
const dataSource = ref([
  {
    name: '参数名称1',
    kongZhiQi: '参数值1',
    beiZhu: '备注1'
  },
  {
    name: '参数名称2',
    kongZhiQi: '参数值2',
    beiZhu: '备注2'
  },
  {
    name: '参数名称3',
    kongZhiQi: '参数值3',
    beiZhu: '备注3'
  }
])

const onSubmit = () => {
  console.log('外接UPS>>')
  onCancel()
}

const onCancel = () => {
  // 触发自定义事件来通知父组件关闭弹窗
  emits('update:visible', false)
}
</script>

<style scoped>
.ant-row {
  margin-bottom: 10px;
}
.y-close-jieneng {
  color: red;
}
</style>